/*
  作者: 劳兆城
  描述: 创建 Format 的方法
*/

import FormatKml from 'ol/format/kml'
import FormatGeoJson from 'ol/format/geojson'
import FormatWKT from 'ol/format/wkt'

// 创建 ol.format.Kml
export const createFormatKml = (options) => new FormatKml(options)

// 创建 ol.format.GeoJson
export const createFormatGeoJson = (options) => new FormatGeoJson(options)

// 读取 feature 的GeoJson
export const createGetFeatureGeoJson = (feature) => {
  let realFeature = null
  if (Array.isArray(feature)) {
    realFeature = feature
  } else {
    realFeature = [feature]
  }

  return createFormatGeoJson().writeFeatures(realFeature, {
    dataProjection: 'EPSG:3857',
    featureProjection: 'EPSG:3857'
  })
}

// 创建 ol.format.WKT
export const createFormatWKT = (options) => new FormatWKT(options)
